<?php
/**
 * Created by PhpStorm.
 * User: 17628
 * Date: 2021-11-04
 * Time: 11:11
 */

namespace app\api\controller;


use app\common\controller\Api;
use app\admin\model\UserTable;
use app\admin\model\Wallet as WalletModel;
class Wallet extends Api
{
    public function index()
    {
        // 获取当前用户id
        $user_id = $this->auth->id;
        // 可提现余额
        $money = UserTable::where(['id' => $user_id])->value('money');
        // 全部
        $all = WalletModel::where(['user_id' => $user_id])->order('id desc')->select();
        // 收入
        $income = WalletModel::where(['user_id' => $user_id])->where('status_switch', 1)->order('id desc')->select();
        // 支出
        $outcome = WalletModel::where(['user_id' => $user_id])->where('status_switch', -1)->order('id desc')->select();

        // 今日拼购奖励(未拼中，奖励金额)
        $today_start = strtotime(date("Y-m-d", time()) . '00:00:00');
        $today_end = strtotime(date("Y-m-d", time()) . '23:59:59');
        $today = WalletModel::where(['user_id' => $user_id, 'status_switch' => 1, 'type' => 3])
            ->whereTime('createtime', [$today_start, $today_end])
            ->sum('money');
        // 今日助力红包、累计助力红包
        $userInfo = UserTable::field('id,today_prize,all_prize')->find($user_id);
        $data = [
            'money' => $money,
            'all' => $all,
            'income' => $income,
            'outcome' => $outcome,
            'today' => $today,
            'today_prize' => $userInfo->today_prize,
            'all_prize' => $userInfo->all_prize,

        ];
        $this->success('获取成功', $data, 1);
    }
}